package com.zwj.liteflow.liteflow.cmp;

import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import com.zwj.liteflow.domain.params.FlowAParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

/**
 * 流程A
 *
 * @author 摸鱼二长老
 * @version 1.0
 * @createTime 2023/8/10 21:42
 */
@Slf4j
@LiteflowCmpDefine
@LiteflowComponent("stepA")
public class StepA extends NodeComponent {

    @Override
    public void process() throws Exception {
        log.info("流程A开始执行======================");
    }

    /**
     * 表示是否进入该节点，可以用于业务参数的预先判断
     *
     * @return
     */
    @Override
    public boolean isAccess() {
        FlowAParam param = this.getRequestData();
        Integer age = param.getAge();
        String gender = param.getGender();
        if (age == null || age < 0 || age > 120) {
            log.info("参数不合法，age不能为空，且age应在 0~120岁之间");
            return false;
        }
        if (!StringUtils.hasText(gender) || (!"男".equals(gender) && !"女".equals(gender))) {
            log.info("参数gender不能为空，且合法值只有【男】或【女】");
            return false;
        }
        return true;
    }
}
